import { Component, OnInit, OnChanges, Input, Output, EventEmitter } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { env } from '../../../environments/index';
@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.scss']
})
export class UploadComponent implements OnChanges {
  public uploadDisable = true;
  public uploadUrl = '';
  public host = env.host;
  @Input() path: string;
  @Output() uploadOk = new EventEmitter();
  constructor(private msg: NzMessageService) {}
  getHeaders() {
    return {
      vf: 'zhangyuegogogo'
    };
  }
  handleChange({ file, fileList }): void {
    const status = file.status;
    if (status === 'done') {
      this.msg.success(`${file.name} 文件上传成功！`);
      this.uploadOk.emit();
    }
  }

  ngOnChanges(data) {
    this.uploadUrl = this.host + '/api/upload/' + this.path;
    this.uploadDisable = this.path ? false : true;
  }
}
